package com.erp.app.admin.systemMenu.web;

//JRE Classes
import java.util.ArrayList;
import java.util.Iterator;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

import com.erp.app.common.ProjectConstants;
import com.erp.framework.controller.form.SimpleMaintStyleForm;
import com.erp.framework.util.CommonUtil;

public class SystemMenuMaintenanceForm extends SimpleMaintStyleForm {

    // T_MENU_GROUP
    private String companyCode;
    private String groupId;
    private String menuId;
    private String parentMenuId;
    private String menuName;
    private String menuType;
    private String menuOrder;
    private String menuUrl;
    private String iconContentType;
    private byte[] menuIcon;
    private String imageContentType;
    private byte[] menuImage;
    private String createDate;
    private String createUser;
    private String updateDate;
    private String updateUser;
    private String rootMenuId;
    private String status;

    // T_MENU_OBJECT
    private String[] objectId;
    private String[] objectName;
    private String[] objectType;
    private String[] objectAction;

    /*
     * Get/Set for Property companyCode
     */
    public String getCompanyCode() {
        return companyCode;
    }

    public void setCompanyCode(String companyCode) {
        this.companyCode = companyCode;
    }

    /*
     * Get/Set for Property groupId
     */
    public String getGroupId() {
        return groupId;
    }

    public void setGroupId(String groupId) {
        this.groupId = groupId;
    }

    /*
     * Get/Set for Property menuId
     */
    public String getMenuId() {
        return menuId;
    }

    public void setMenuId(String menuId) {
        this.menuId = menuId;
    }

    /*
     * Get/Set for Property parentMenuId
     */
    public String getParentMenuId() {
        return parentMenuId;
    }

    public void setParentMenuId(String parentMenuId) {
        this.parentMenuId = parentMenuId;
    }

    /*
     * Get/Set for Property menuName
     */
    public String getMenuName() {
        return menuName;
    }

    public void setMenuName(String menuName) {
        this.menuName = menuName;
    }

    /*
     * Get/Set for Property menuType
     */
    public String getMenuType() {
        return menuType;
    }

    public void setMenuType(String menuType) {
        this.menuType = menuType;
    }

    /*
     * Get/Set for Property menuOrder
     */
    public String getMenuOrder() {
        return menuOrder;
    }

    public void setMenuOrder(String menuOrder) {
        this.menuOrder = menuOrder;
    }

    /*
     * Get/Set for Property menuUrl
     */
    public String getMenuUrl() {
        return menuUrl;
    }

    public void setMenuUrl(String menuUrl) {
        this.menuUrl = menuUrl;
    }

    /*
     * Get/Set for Property iconContentType
     */
    public String getIconContentType() {
        return iconContentType;
    }

    public void setIconContentType(String iconContentType) {
        this.iconContentType = iconContentType;
    }

    /*
     * Get/Set for Property menuIcon
     */
    public byte[] getMenuIcon() {
        return menuIcon;
    }

    public void setMenuIcon(byte[] menuIcon) {
        this.menuIcon = menuIcon;
    }

    /*
     * Get/Set for Property imageContentType
     */
    public String getImageContentType() {
        return imageContentType;
    }

    public void setImageContentType(String imageContentType) {
        this.imageContentType = imageContentType;
    }

    /*
     * Get/Set for Property menuImage
     */
    public byte[] getMenuImage() {
        return menuImage;
    }

    public void setMenuImage(byte[] menuImage) {
        this.menuImage = menuImage;
    }

    /*
     * Get/Set for Property createDate
     */
    public String getCreateDate() {
        return createDate;
    }

    public void setCreateDate(String createDate) {
        this.createDate = createDate;
    }

    /*
     * Get/Set for Property createUser
     */
    public String getCreateUser() {
        return createUser;
    }

    public void setCreateUser(String createUser) {
        this.createUser = createUser;
    }

    /*
     * Get/Set for Property updateDate
     */
    public String getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(String updateDate) {
        this.updateDate = updateDate;
    }

    /*
     * Get/Set for Property updateUser
     */
    public String getUpdateUser() {
        return updateUser;
    }

    public void setUpdateUser(String updateUser) {
        this.updateUser = updateUser;
    }

    /*
     * Get/Set for Property objectId[]
     */
    public String[] getObjectId() {
        return objectId;
    }

    public void setObjectId(String[] objectId) {
        this.objectId = objectId;
    }

    /*
     * Get/Set for Property objectName[]
     */
    public String[] getObjectName() {
        return objectName;
    }

    public void setObjectName(String[] objectName) {
        this.objectName = objectName;
    }

    /*
     * Get/Set for Property objectType[]
     */
    public String[] getObjectType() {
        return objectType;
    }

    public void setObjectType(String[] objectType) {
        this.objectType = objectType;
    }

    /*
     * Get/Set for Property objectAction[]
     */
    public String[] getObjectAction() {
        return objectAction;
    }

    public void setObjectAction(String[] objectAction) {
        this.objectAction = objectAction;
    }

    public void otherReset(ActionMapping mapping, HttpServletRequest request) {
        String emptyString = "";
    }

    public void otherValidate(ActionErrors errors) {

        if (CommonUtil.isEmpty(this.menuId)) {
            errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.general.field.blank", "Menu ID"));
        } else {
            menuId = menuId.trim().toUpperCase();
        }

        if (CommonUtil.isEmpty(this.groupId)) {
            errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.general.field.blank", "Group ID"));
        } else {
            groupId = groupId.trim().toUpperCase();
        }

        ArrayList checkList = new ArrayList();

        // menu items
        ArrayList rows = getMultiRows(0);
        Iterator iterator = rows.iterator();
        while (iterator.hasNext()) {
            SystemMenuObjectRow row = (SystemMenuObjectRow) iterator.next();

            if (row == null)
                continue;
            if (!CommonUtil.isEmpty(row.getIsDelete()))
                continue;

            String currentObjectId = CommonUtil.nullToString(row.getObjectId());

            if (CommonUtil.isEmpty(currentObjectId)) {
                errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.general.field.blank", "Menu Object ID"));
                return;
            } else {
                row.setObjectId(currentObjectId.trim().toUpperCase());
                row.setMenuId(menuId);
            }

            if (checkList.contains(row.getObjectId())) {
                errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.general.key.duplicate", row.getObjectId()));
                return;
            } else {
                checkList.add(row.getObjectId());
            }

            row.setMenuId(menuId);
            row.setGroupId(groupId);
        }

        checkList.clear();
        checkList = null;

        String[] tempIdArray = this.getObjectId();
        String tempStr = null;
        if (tempIdArray != null) {
            for (int i = 0; i < tempIdArray.length; i++) {
                tempStr = tempIdArray[i];
                if (tempStr != null) {
                    tempIdArray[i] = tempStr.trim().toUpperCase();
                }
            }
        }
    }

    public String getRootMenuId() {
        return rootMenuId;
    }

    public void setRootMenuId(String rootMenuId) {
        this.rootMenuId = rootMenuId;
    }

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

}
